package com.renjiyue.GUI;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Iterator;

public class GUIDome15 {
    public static void main(String[] args) {
        new MyFrame02("drawing....");
    }
}
class MyFrame02 extends Frame{
    ArrayList points = null;
    MyFrame02(String s){
        super(s);
        points = new ArrayList();
        setLayout(null);
        setBounds(200,200,400,300);
        this.setBackground(new Color(204,204,255));
        setVisible(true);
        this.addMouseListener(new Monitor());
    }
    public void paint(Graphics g){
        Iterator i = points.iterator();
        while(i.hasNext()){
            Point p = (Point)i.next();
            g.setColor(Color.BLUE);
            g.fillOval(p.x,p.y,10,10);
        }
    }
    public void addPoint(Point p){
        points.add(p);
    }
    private class Monitor extends MouseAdapter{
        @Override
        public void mousePressed(MouseEvent e) {
            MyFrame02 frame = (MyFrame02)e.getSource();
            frame.addPoint(new Point(e.getX(),e.getY()));
            frame.repaint();
        }
    }
}